home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18363 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  61 lines

  1. Path: service-2.agate.net!usenet
  2. From: ettienne@agate.net (Steve Nutt)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ guru sought ...
  5. Date: Sat, 20 Apr 1996 05:07:30 GMT
  6. Organization: DET
  7. Message-ID: <4l9k16$mbo@service-2.agate.net>
  8. References: <316CB5B5.41C6@cs.york.ac.uk>
  9. Reply-To: ettienne@agate.net
  10. NNTP-Posting-Host: ettienne.sdi.agate.net
  11. X-Newsreader: Forte Free Agent 1.0.82
  12.  
  13. John Kennedy <johnk@cs.york.ac.uk> wrote:
  14.  
  15. >Hi there,
  16.  
  17. >I have an interesting C++ problem that I was wondering if any guru out
  18. >there knows the answer to....  
  19.  
  20. >I am trying to create a template class that saves or reads data to/from
  21. >a file.  This is not a problem for numeric data as fstream can cope with
  22. >this no problem.  The problem I have is that when the template type is a
  23. >string I have to create the space to store the data in. The only way I
  24. >can see of doing this is to use a case statement in the template
  25. >function but this is then removing all purpose of creating a template in
  26. >the first place.
  27.  
  28. >Does anyone know a way around this problem ?
  29.  
  30. >John Kennedy
  31.  
  32. >johnk@cs.york.ac.uk
  33.  
  34. I don't think I quite follow the problem here. Why do you need the
  35. case statement?
  36.  
  37. I've used a class similar to
  38.  
  39. template <size_t size> class _export TString
  40. {
  41. public:
  42.     TString (void)
  43.         {
  44.         c[0] = 0;
  45.         }
  46.  
  47.     TString (const TString <size>& other) 
  48.         {
  49.         strcpy (c, other.c);
  50.         }
  51.  
  52. private:
  53.  
  54.     char c[size +1];
  55. };
  56.  
  57. when I've not wanted to use the Borland string class.
  58.  
  59. Steve
  60.  
  61.